package fhp.hlhj.giantfold.activity.annualized

import android.content.Intent
import android.view.Gravity
import com.lzy.okgo.model.HttpParams
import fhp.hlhj.giantfold.BaseActivity
import fhp.hlhj.giantfold.Contents
import fhp.hlhj.giantfold.R
import fhp.hlhj.giantfold.interfaces.AnnualizedView
import fhp.hlhj.giantfold.customView.AnnualizedPop
import fhp.hlhj.giantfold.interfaces.IAnnual
import fhp.hlhj.giantfold.javaBean.EFBean
import fhp.hlhj.giantfold.presenter.AnnualPresenter
import fhp.hlhj.giantfold.utils.LogUtil
import kotlinx.android.synthetic.main.activity_annualized_aty.*

class AnnualizedAty : BaseActivity(), AnnualizedView, IAnnual {
    private lateinit var annualPresenter:AnnualPresenter

    /**
     * 提升年化率
     */
    override fun levelAnnual(page:Int) {
        val p = AnnualizedPop(this@AnnualizedAty,page)
        p.showAtLocation(father,Gravity.CENTER,0,0)
        val lp = window.attributes
        lp.alpha = 0.7f
        window.attributes = lp
        p.setOnDismissListener {
            val lp = window.attributes
            lp.alpha = 1f
            window.attributes = lp
        }
    }

    override fun getContentId(): Int = R.layout.activity_annualized_aty

    override fun initView() {
        annualPresenter= AnnualPresenter(this)
        val params = HttpParams()
        params.put("user_id",Contents.userId)
        annualPresenter.getEf(params)
    }

    override fun initListener() {
        btExit.setOnClickListener {
            finish()
        }
        btLevelUp.setOnClickListener {
//            levelAnnual()
            startActivity(Intent(this,ShowAnnualAty::class.java))
        }
        tv1.setOnClickListener {
            levelAnnual(0)
        }
        tvFriend.setOnClickListener {
            levelAnnual(0)
        }
        tv2.setOnClickListener {
            levelAnnual(1)
        }
        tvBuy.setOnClickListener {
            levelAnnual(1)
        }
        tv3.setOnClickListener {
            levelAnnual(2)
        }
        tvSpend.setOnClickListener {
            levelAnnual(2)
        }
        tv4.setOnClickListener {
            levelAnnual(3)
        }
        tvFrequency.setOnClickListener {
            levelAnnual(3)
        }
        tv5.setOnClickListener {
            levelAnnual(4)
        }
        tvShare.setOnClickListener {
            levelAnnual(4)
        }
    }


    override fun showLoading() {
        loadingDialog.show()
    }

    override fun onResp(efBean: EFBean) {
        loadingDialog.dismiss()
        if (efBean.code==200){
            tvFriend.text=efBean.data.friend_invite
            tvBuy.text=efBean.data.shopping_action
            tvSpend.text=efBean.data.consumption_ability
            tvFrequency.text=efBean.data.use_frequency
            tvShare.text=efBean.data.sharing_frequency
            progress.progress=efBean.annual_rate_level*20
        }
    }
}




